<template>
  <div class="list">
    <el-row>
      <el-form ref="form" :model="form" label-width="80px" :inline="true">
        <el-form-item label="交易账户">
          <el-input v-model="form.account" placeholder="请输入交易账户"></el-input>
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="form.type" placeholder="请选择类型">
            <el-option label="买入" value="0"></el-option>
            <el-option label="卖出" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search()">搜索</el-button>
          <el-button @click="resetForm()">重置</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="序号" width="50">
      </el-table-column>
      <el-table-column prop="account" label="交易账户">
      </el-table-column>
      <el-table-column prop="open_time" label="开仓时间">
      </el-table-column>
      <el-table-column prop="trade_breed" label="交易品种">
      </el-table-column>
      <el-table-column prop="position_sn" label="仓位单号">
      </el-table-column>
      <el-table-column prop="type" label="类型(仓位订单方向)">
        <template slot-scope="{row}">
          <span v-if="row.type == 0">买入</span>
          <span v-if="row.type == 1">卖出</span>
        </template>
      </el-table-column>
      <el-table-column prop="volume" label="交易手数">
      </el-table-column>
      <el-table-column prop="open_price" label="开仓价格">
      </el-table-column>
      <el-table-column prop="tp" label="止盈价格">
      </el-table-column>
      <el-table-column prop="sl" label="止损价格">
      </el-table-column>
      <el-table-column prop="close_time" label="平仓时间">
      </el-table-column>
      <el-table-column prop="close_price" label="平仓价格">
      </el-table-column>
      <el-table-column prop="commission" label="手续费">
      </el-table-column>
      <el-table-column prop="swap" label="隔夜利息">
      </el-table-column>
      <el-table-column prop="profit" label="盈利">
      </el-table-column>
      <el-table-column prop="balance" label="余额">
      </el-table-column>
      <el-table-column prop="equity" label="净值">
      </el-table-column>

      <!-- <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="toEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="toDel(scope.row.id)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination background layout="total,prev, pager, next" :total="total" :page-size="size" @prev-click="prev()"
      @next-click="next()" @current-change="currentchange" style="margin-top: 20px;">
    </el-pagination>
  </div>
</template>

<script>
  import {
    ajaxPost
  } from "@/api/ajax"
  export default {
    name: "list",
    data() {
      return {
        tableData: [],
        page: 1,
        size: 15,
        total: 0,
        current_page: 1,
        form: {
          account: '',
          type: '',
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        let data = {
          page: this.page,
          size: this.size,
          account: this.form.account,
          type: this.form.type,
        };
        ajaxPost('order/list', data).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.data;
            this.total = res.data.total;
            this.current_page = res.data.current_page;
          }
        })
      },
      search() {
        this.getList();
      },
      prev() {
        this.page -= 1;
        this.getList();
      },
      next() {
        this.page += 1;
        this.getList();
      },
      currentchange(value) {
        this.page = value;
        this.getList();
      },
      editStatus(val) {
        ajaxPost("article/editStatus", val).then(res => {
          if (res.code == 0) {
            this.getList();
          }
        })
      },
      toEdit(row) {
        this.$router.push({
          name: 'article_edit',
          params: row
        });
      },
      toDel(id) {
        this.$confirm('确认删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          ajaxPost('article/delete', {
            id: id
          }).then(res => {
            if (res.code == 0) {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
            } else {
              this.$message({
                type: 'error',
                message: '删除失败!'
              });
            }
          })
          this.getList();
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      resetForm(formName) {
        this.form = {
          account:"",
          type:"",
        }
        this.getList();
      }
    },
  }
</script>

<style>
  .list {
    padding: 20px;
    box-sizing: border-box;

    .search-input {
      width: 150px;
    }

    .list-page {
      margin-top: 20px;
    }
  }
</style>
